from enum import Enum
from typing import List
from pydantic import BaseModel, validator, conint


class ActivityStatisticPivot(str, Enum):
    active_person = "active_person"
    institution = "institution"
    business = "business"


class ActivityStatisticParams(BaseModel):
    year: conint(ge=1990, le=2080) = None
    stats_pivot: ActivityStatisticPivot


class RegisterRecordStatisticParams(BaseModel):
    """
    参加会议记录相关的统计参数
    """
    person_id: str
    year_range: List[int]

    @validator("year_range")
    def valid_year_range(cls, v):
        if len(v) != 2:
            raise ValueError("missing range items")
        for item in v:
            if item < 1990 or item > 2050:
                raise ValueError("invalid year")
        return v


if __name__ == '__main__':
    import json

    print(json.dumps(ActivityStatisticParams.schema()))
